package be.ipl.eBar.domaine;

import java.io.Serializable;

import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.IdClass;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
import javax.validation.constraints.NotNull;

@SuppressWarnings("serial")
@Entity
@Table(name = "COMMANDES_BIERES", schema = "EBAR")
@IdClass(LignePK.class)
public class Ligne implements Serializable {
	@Id
	@ManyToOne
	@JoinColumn(name = "BIERE_ID")
	private Biere biere;
	@Id
	@ManyToOne
	@JoinColumn(name = "COMMANDE_ID")
	private Commande commande;
	@NotNull
	private int quantite;

	protected Ligne() {
	}

	public Ligne(Biere biere, Commande commande, int quantite) {
		this.biere = biere;
		this.commande = commande;
		this.quantite = quantite;
	}

	public int getQuantite() {
		return quantite;
	}

	public void setQuantite(int quantite) {
		this.quantite = quantite;
	}

	public Biere getBiere() {
		return biere;
	}

	public Commande getCommande() {
		return commande;
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + ((biere == null) ? 0 : biere.hashCode());
		result = prime * result
				+ ((commande == null) ? 0 : commande.hashCode());
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		Ligne other = (Ligne) obj;
		if (biere == null) {
			if (other.biere != null)
				return false;
		} else if (!biere.equals(other.biere))
			return false;
		if (commande == null) {
			if (other.commande != null)
				return false;
		} else if (!commande.equals(other.commande))
			return false;
		return true;
	}

}
